package homework4.test;

/**
 * @author fengq
 */
public class CommunicateThread implements Runnable{
    @Override
    synchronized public void run() {
        for (int i=0;i<5;i++){
            System.out.println(Thread.currentThread().getName()+i);
            if (i==2){
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            if (i==1){
                //从等待队列唤醒a线程进入等待
                notify();
            }
            if (i==4){
                //唤醒线程tb
                notify();
            }
        }
    }

    public static void main(String[] args) {
        CommunicateThread thread = new CommunicateThread();
        Thread thread1 = new Thread(thread, "线程ta");
        Thread thread2 = new Thread(thread, "线程tb");
        thread1.start();
        thread2.start();
    }

}
